package com.eningqu.aipen.ui.base;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.eningqu.aipen.utils.ActivityController;
import com.eningqu.aipen.utils.ZKStatusBarUtil;

/**
 * Package:com.eningqu.aipen.ui.base
 * Author:starr
 * Time:2023/9/14  10:38
 * Description:基类Activity 封装DataBinding
 */
public abstract class BaseActivity<VB extends ViewDataBinding> extends AppCompatActivity {
    protected VB mBinding;

    private final static String TAG="BaseActivity";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: "+getClass().getSimpleName());
        ActivityController.getInstance().addActivity(this);
        initActivity();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityController.getInstance().removeActivity(this);
    }

    /**
     * 获取布局id
     */
    protected abstract int getLayoutId();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    /**
     * 初始化布局
     */
    private void initLayout(){
        mBinding= DataBindingUtil.inflate(
                LayoutInflater.from(this),
                getLayoutId(),
                null,
                false);
        setContentView(mBinding.getRoot());
    }
    /**
     * 初始化Activity
     */
    protected void initActivity(){
        //透明状态栏
        ZKStatusBarUtil.setTransparentForWindow(this);
        ZKStatusBarUtil.setDarkMode(this);
        initLayout();
        initView();
        initData();
        async();
    }

    public Context getContext(){
        return this;
    }


    /**
     * 用于子类实现
     */
    protected  void async(){

    }
}
